<?php
//数据统计模型
class StaticModel extends CommonModel {
	
	private $actionArr = array('add','delete','update');
	/**
	 * 更新统计数据  日记记录
	 * @param int    $cid       栏目id
	 * @param string $action    操作        |   增加 add  删除 delete 修改 update 
	 * @param string $desc      操作描述 
	 */
	public function updateStaticAndLog($cid,$action,$operateid=0,$desc='')
	{
		$webId = isset($_SESSION['wid']) ? intval($_SESSION['wid']) : 0 ;
		$cid   = intval($cid);
		if(!$webId || !$cid || !$action)  return;
		$action = strtolower($action);
		//记录日志
		$logModel = D('Log');
		$logModel->writeLog($cid,$action,$operateid,$desc);
		if(in_array($action,$this->actionArr))
		{
			$table = 'douhao_static';
			$field = $action.'_num';
			$nowTime = date('Y-m-d H:i:s');
			//更新
			$ret = $this->query("update {$table}  set $field = $field +1,last_operate_time = '".$nowTime."' where cid = ".$cid);
			if(!$ret)
			{
				//保存信息
				$this->add(array('cid'=>$cid,$field=>1,'last_operate_time'=>$nowTime));
			}
			//切回主库 信息入主库
			$allow = 0;
			if($allow)
			{
				$this->query('use '.C('DB_NAME'));
				//开始统计
				$this->query("update {$table}  set $field = $field +1,last_operate_time = ".date('Y-m-d H:i:s'." where webid = ".$webId));
			}
		}
	}
	//统计列表
	public function getStaticList()
	{
		
		$sql="select 
						co.column_name,static.*
				  from 
				  		douhao_website_column as co  ,
				  		douhao_static as `static`
				  where
				        co.id = static.cid and co.status = '1' order by co.id asc
			";
		$list = $this->query($sql); 
		return $list;
	}
}
	
?>